package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.CurrentUser;
import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.po.ExamPaper;
import com.zhijian.medical.entity.vo.request.ExamPaperSearchVo;
import com.zhijian.medical.entity.vo.request.ExamSubmitVo;
import com.zhijian.medical.entity.vo.response.ExamPaperVo;
import com.zhijian.medical.entity.vo.response.ExamResultVo;
import com.zhijian.medical.service.ExamPaperService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 考核-试卷模块 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-01-18 16:13:08
 */
@Slf4j
@Controller
@Api(tags = "考核-试卷模块")
public class ExamPaperController {

    @Autowired
    private ExamPaperService service;

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/exam/paper/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/exam/paper/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody ExamPaper param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/exam/paper/{id}")
    @ApiOperation("根据id查询")
    public ExamPaperVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/exam/paper/page")
    @ApiOperation("分页查询")
    public Page<ExamPaperVo> selectByCondition(@RequestBody(required = false) ExamPaperSearchVo param) {
        if (param == null)
            param = ExamPaperSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

//    /**
//     * 详情，用作考试的时候显示
//     *
//     * @param id
//     * @return
//     */
//    @Response
//    @GetMapping("/exam/paper/singleDetail/{id}")
//    @ApiOperation("详情，用作考试的时候显示")
//    public ExamDoingVo singleDetail(@CurrentUser @ApiIgnore PersonDto personDto, @PathVariable("id") Long id) {
//        return service.singleDetail(personDto.getId(), id);
//    }

    /**
     * 提交试卷，or中途保存
     *
     * @return
     */
    @Response
    @PostMapping("/exam/paper/submit")
    @ApiOperation("提交试卷，or中途保存")
    public ExamResultVo submit(@CurrentUser @ApiIgnore PersonDto personDto, @RequestBody ExamSubmitVo examSubmitVo) {
        examSubmitVo.setUserId(personDto.getId());
        log.info("exam submit,the param is {}", examSubmitVo);
        return service.submit(examSubmitVo);
    }

}